<?php

class OauthshowAction {

    public function index() {
        switch ($_GET['type']) {
            case 'weibo':
                $this->performWeibo();
                break;
            case 'baidu':
                $this->performBaidu();
                break;
            case 'qq':
                include COMMON_PATH . 'oauth2/qq/oauth/qq_login.php';
                break;
            case 'kaixin':
                $this->performKaixin();
                break;
            default:
        }
    }

    public function performKaixin() {
        include COMMON_PATH . 'oauth2/kaixin/kxoauth/kxClient.php';
        import('@.ORG.Session');
        $connection = new KXClient();

        $scope = 'create_records create_album user_photo friends_photo upload_photo';
        $login_url=$connection->getAuthorizeURL('code', $scope);
         header("Location:$login_url");
    }

    private function performWeibo() {
        include COMMON_PATH . 'oauth2/weibo/config.php';
        include COMMON_PATH . 'oauth2/weibo/saetv2.ex.class.php';
        import('@.ORG.Session');
        $o = new \SaeTOAuthV2(WB_AKEY, WB_SKEY);

        $login_url = $o->getAuthorizeURL(WB_CALLBACK_URL);
        header("Location:$login_url");
    }

    private function performBaidu($param) {
        include COMMON_PATH . 'oauth2/baidu/Baidu.php';
        include COMMON_PATH . 'oauth2/weibo/BaiduStore.php';
        import('@.ORG.Session');
        $baidu = new Baidu('llYR1Ba1cZ3uwEX4tcbO6QL5', 'obh5DcqzusMmhxrlh8tlGYjHYt5px5OS',
                        new BaiduSessionStore('llYR1Ba1cZ3uwEX4tcbO6QL5'));
        $baidu->useHttps();
        $login_url = $baidu->getLoginUrl(array('response_type' => 'code',
            'display' => 'popup',
            'redirect_uri' => 'http://quwanma.sinaapp.com/oauth/?type=baidu'));

        header("Location:$login_url");
    }

}